import * as api from "../../api/index";
import * as toast from  '@/util/toast/toast'
import User from '../../store/user'
import * as btUtil from '@/util/bluetoothUtil/btUtil'
import * as router from '@/util/router/router'
import store from '@/store/store'
import { types } from "sass";

export default class connenctBluetoothUtil{

    ///是否展示配对蓝牙的倒计时弹窗
    isShowMatchBluetoothLoading:Boolean = false;

    ///配对蓝牙的倒计时计数器
    matchBluetoothTimerCount:number = 10;
    isStartBluetoothBindStatus = false;   
    isInitedBlueTooth = false;   
    autoRefreshTime = -1;//自动刷新定时器
    bindTimeCountTimer = -1;//绑定倒计时的定时器
    bindTimeCounter = 0; //绑定设备的倒计时的计数器
    startQueryDate = null as any;//开始查询实时数据的时间
    searchedResList = [] as any; //搜索到的蓝牙列表

    lastConnectModal = null as any; //配对模态弹窗


    deviceLastOpenStatus = ''; ///设备的上一次的开关机状态
    deviceLastModeStatus = ''; ///设备的上一次的模式状态


   searchBluetoothListCallback = null as any; ///搜索蓝牙列表的回调
   connectBluetoothCallback = null as any; ///连接指定蓝牙的回调


   isReceiveData = false; ///是否结束监听
   isSendUnionIdCMD = false; //是否发送了蓝牙协议id
//    constructor(){

//    }

    exportSearchBluetoothWithCallback(callback:any){///对外-开始搜索蓝牙列表
        this.searchedResList = []
        this.searchBluetoothListCallback = callback as any
        if( User.isInitBlueTooth){
            this.closeBluetoothAdapter();
        }else{
            this.initBluthtooth()
        }
       
    }

    exportRefreshBluetoothSearchWithcallback(callback:any){ //刷新蓝牙搜索
        this.searchedResList = []
        this.searchBluetoothListCallback = callback as any
        if( User.isInitBlueTooth){
            this.stopSearchAction(true);
        }else{
            this.initBluthtooth()
        }
    }
    
    exportConnectBluetooth(item:any,callback:any){//对外-开始连接蓝牙
        this.deviceLastModeStatus = ''
        this.deviceLastOpenStatus = ''
        this.connectBluetoothCallback = callback;
        this.connectBluetooth(item)
    }
    
 

//    -----------------蓝牙搜索方法--------------
    initBluthtooth(){ ///初始化蓝牙模块
    let self = this
    console.log('开始初始化蓝牙')

        uni.openBluetoothAdapter({
            success(res) {
                User.isInitBlueTooth = true
                self.isInitedBlueTooth = true
                self.onListenBlietoothStatusChanged()
                self.stopSearchAction(true)
            },fail(err){
                let errMsg = err.errMsg
                let isOpened = errMsg.includes('opened')
                console.log('初始化蓝牙报错：'+errMsg)
                if(isOpened){
                    User.isInitBlueTooth = true
                    self.stopSearchAction(true)
                }else{
                    User.isInitBlueTooth = false
                    self.searchBluetoothListCallback(false,null)

                }
                // toast.infoToast(err.errMsg)
            }
        })
   }
   onListenBlietoothStatusChanged(){
        uni.onBluetoothAdapterStateChange(function (res) {
            if(res.available === false){
                User.isInitBlueTooth = false
            }
        })


        uni.onBLEConnectionStateChange(function (res) {
            if(res.connected === false){
                User.isInitBlueTooth = false
            }
        })
   }
   closeBluetoothAdapter(){
    let self = this;
    uni.closeBluetoothAdapter({
        success(res) {
            User.isInitBlueTooth = false
            console.log('关闭蓝牙模块成功')
          self.initBluthtooth()
        },
        fail(result) {
            console.log('关闭蓝牙模块s失败')
        },
      })
    }
   findBlueList(){ ///开始搜索新蓝牙
    console.log('开始搜索蓝牙')
    let self = this

   

    uni.onBluetoothDeviceFound(function (devices:any) {
        let list = devices.devices
        // console.log('搜索到蓝牙：'+JSON.stringify(list))

        if(list.length > 0){
            let device = list[0]
            let isFind = false
            self.searchedResList.forEach((element:any) => {
                if(element.deviceId === device.deviceId){
                    isFind = true
                }
            });
            if(isFind === false && device.name.length > 0 && (device.name.includes('JLC') || device.name.includes('proj_at'))){
                self.searchedResList.push(device)
            }
            

            self.searchBluetoothListCallback(true,self.searchedResList)
        }

    })


    // 以微信硬件平台的蓝牙智能灯为例，主服务的 UUID 是 FEE7。传入这个参数，只搜索主服务 UUID 为 FEE7 的设备
    uni.startBluetoothDevicesDiscovery({
        services: [],
        success(res) {
            console.log('开启蓝牙搜索成功：'+JSON.stringify(res))
        },
        fail(err){
            console.log('搜素蓝牙报错：'+JSON.stringify(err))

        }
    })
   }

//    -----------------蓝牙连接方法--------------
   connectBluetooth(item:any){ ///连接蓝牙
    let self = this;
    this.isSendUnionIdCMD = false;
    this.isStartBluetoothBindStatus = false;
    User.bluetoothCallbackData.string_device_union_id_data = ''
    console.log('读取准备连接的蓝牙的id:'+User.currentConnectedBlueTooth.deviceId)

    //  let deviceId = User.currentConnectedBlueTooth.deviceId;

    //  if(deviceId !== null || deviceId !== undefined){
    //     console.log('已经连接过蓝牙的id:'+deviceId+'准备端开')

    //     //如果已经连接上了蓝牙，先把连接的断开再连接新的
    //      User.currentConnectedBlueTooth = {} as any;
    //          uni.closeBLEConnection({
    //          deviceId,
    //          success(res) {
    //          self.didStartConnectBle(item);
    //          },fail(result) {
    //              self.didStartConnectBle(item);
    //          },
    //      });
    //  }else{
         this.didStartConnectBle(item);

    //  }
 }
    didStartConnectBle(item:any){///执行连接蓝牙的错做
        let self = this;
        User.isTempConnectedBlueTooth = false;
        User.isReceivedRuntimeData = false;
        //停止发送实时数据的查询
        self.stopAutoRefreshTimer()
        let deviceId = item.deviceId
        uni.createBLEConnection({
            // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
            deviceId,
            success(res) {
                ///蓝牙连接上了，后续还要查询服务uuid和特征值uuid
                User.isTempConnectedBlueTooth = true;
                User.currentConnectedBlueTooth = item;
                //查询服务和特征值
                self.queryConnectedBlueToothServices()
               
                self.stopSearchAction(false);



            },
            fail(res) {
                console.log('蓝牙连接失败：'+JSON.stringify(res));
                self.connectFailedAndBackAction();
            }
        })
    }

   queryConnectedBlueToothServices(){ ///获取连接蓝牙的服务
        let self = this
        let deviceId = User.currentConnectedBlueTooth.deviceId

        uni.getBLEDeviceServices({
            deviceId: deviceId,
            success(res) {
                console.log('连接蓝牙的服务:'+JSON.stringify(res))
                let list = res.services
                if(list.length > 0){
                    let service = list[0] as any
                    User.currentConnectedBlueTooth.service = service.uuid
                    ///查询特征值
                    self.queryConnectedBlueToothServicesCharacteristics()
                }


            },
            fail(err) {
                console.error(err)
                self.connectFailedAndBackAction();
            }
        });
   }
   queryConnectedBlueToothServicesCharacteristics(){ ///获取连接蓝牙服务的特征值
    let self = this




        let deviceId = User.currentConnectedBlueTooth.deviceId
        let service = User.currentConnectedBlueTooth.service


        uni.getBLEDeviceCharacteristics({
            deviceId: deviceId, 
            serviceId: service, 
            success(res) {
                let list = res.characteristics
                console.log('连接蓝牙服务的特征值:'+JSON.stringify(res))

                if(list.length > 0){
                    let characteristic = list[0] as any
                    console.log('取出来的特征值:'+JSON.stringify(characteristic));

                    User.currentConnectedBlueTooth.characteristic = characteristic.uuid
                    console.log('存储的特征值uuid:'+User.currentConnectedBlueTooth.characteristic);

                    ///开启数据回写监听
                    self.onListenBleData()

                    //判断是否能够拿到实时数据
                    self.startAutoRefreshTimer()
                    console.log('开启定时器查询');

                }
            },
            fail(err) {
                console.error(err)
                self.connectFailedAndBackAction();
            }
        })

    }
   startAutoRefreshTimer(){//开启定时刷新定时器


        if(User.isTempConnectedBlueTooth === false){
            return
        }
         //记录开始查询的时间
         this.startQueryDate = new Date()
        this.stopAutoRefreshTimer()
        this.autoQueryRuntimeData();

        console.log('定时器开启')


      
        let self = this
        this.autoRefreshTime = setInterval(() => {
            self.autoQueryRuntimeData();

        }, 1850);
    }
   stopAutoRefreshTimer(){//关闭定时刷新定时器
        if(this.autoRefreshTime !== -1){
            clearInterval(this.autoRefreshTime)
            this.autoRefreshTime = -1
        }
    }
   autoQueryRuntimeData(){//自动查询实时数据

        console.log('定时方法执行')


        let self = this

        let now = new Date()

        let interval = Math.abs(now.getTime() - this.startQueryDate.getTime()) / 1000;
        //如果超时10秒，就进行提示
        let isReceivedRuntimeData = User.isReceivedRuntimeData
        if(interval >= 10 && !isReceivedRuntimeData){
            console.log('超时没有拿到蓝牙数据');
                ///回调蓝牙连接失败
            this.connectSuccessAndHanerOther(false);
            toast.hideLoading()

            this.stopAutoRefreshTimer()
            uni.showModal({
                title: '设备连接超时，请检查设备运行是否正常，如设备确定运行正常请重试',
                confirmText:'重试',
                cancelText:'取消',
                success: function (res) {
                    if (res.confirm) {
                        //重试
                        self.startAutoRefreshTimer()
                    }else{
                        self.closeBluetoothConnect()
                       
                    }
                }
            });
            return
        }

        console.log('发送查询实时数据的蓝牙指令')

        btUtil.getDeviceRuntimeDataWithcomplete(function(res:any){
            

        })
    }
    stopSearchAction(needSearch:boolean){ ///关闭搜索
        let self = this
    
        console.log('关闭搜索')
        uni.stopBluetoothDevicesDiscovery({
            success(res) {
                console.log('关闭搜索成功，开始搜索')

                if(needSearch){
                    self.findBlueList()
    
                }
            },
            fail(err){
                console.log('关闭失败:'+JSON.stringify(err))
                // toast.infoToast(err.errMsg)
                if(needSearch){
                    console.log('关闭搜索失败，开始搜索')

                    self.findBlueList()
    
                }
            }
        })
       }

//  -----------------判断连接的蓝牙是否已绑定激活-----------------
queryBluetoothUnionId(){//查询当前设备的唯一id
    let self = this
    btUtil.getDeviceUnionIDWithcomplete(function(res5:any){
        console.log('读取蓝牙协议id结果：'+res5)
    });

}
startBlueToothBindStatusProgress(){ //进入蓝牙绑定状态判断流程
  let self = this;
  uni.getNetworkType({
    success: function (res) {
      console.log(res.networkType);
      if (res.networkType === 'none') {
        let msg = '无法连接网络，检查网络设置是否正常。'
        uni.showModal({
            content: msg,
            confirmText:'知道了',
            showCancel:false,
            success: function (res) {
                if (res.confirm) {
                    self.closeBluetoothConnect()
                    router.back()
                }
            }
        });
      } else {
        self.judgeDeviceIsBind()
      }
    }
  });
}

judgeDeviceIsBind(){//判断当前设备有没有绑定了蓝牙

    let self = this;

    let connectedBluetoothid = User.bluetoothCallbackData.string_device_union_id_data as any
    connectedBluetoothid = connectedBluetoothid !== null && connectedBluetoothid !== '' ? connectedBluetoothid : '-1'
    console.log('当前连接蓝牙的蓝牙协议id：'+connectedBluetoothid)


    console.log('开始查询当前选择设备绑定的蓝牙协议')
    let param = {'deviceid':User.tempChoosedEquipDeviceId};
    api.queryBlueToothIdByDeviceIdReq(param).then(function(res:any){
        console.log('根据设备id：'+User.tempChoosedEquipDeviceId+'查蓝牙协议id：'+JSON.stringify(res))

        if(res.success){
            let bindBluetoothId = res.data.bluetoothID
            console.log('当前选择设备绑定的蓝牙协议id：'+bindBluetoothId)

            ////tofix
            // bindBluetoothId = '0C0037004200115031563836372098' 
            if(bindBluetoothId !== null && bindBluetoothId !== ''){
                console.log('当前选择设备已绑定过蓝牙：')
                if(connectedBluetoothid === '-1'){
                    console.log('连接蓝牙的是老版本设备无蓝牙协议，记录激活时间并返回连接成功');
                    self.recordOldBluetoothActiveTimeReq()
                      
                        
                }else if(bindBluetoothId !== connectedBluetoothid){
                    toast.hideLoading()

                    console.log('设备蓝牙id与连接蓝牙id不一致，断开连接');
                    let msg = '当前ID:'+connectedBluetoothid+'的蓝牙，非本设备绑定的协议ID!'


                    // let msg = '蓝牙配对失败，该设备'+User.tempChoosedEquipDeviceId+'已被蓝牙ID'+bindBluetoothId+'绑定，请确认'
                    uni.showModal({
                        content: msg,
                        confirmText:'知道了',
                        showCancel:false,
                        success: function (res) {
                            if (res.confirm) {
                                self.closeBluetoothConnect()
                                router.back()
                            }
                        }
                    });

                }else{
                    console.log("设备协议绑定过蓝牙，与当前蓝牙协议一致，再查询蓝牙协议绑定的设备");

                    self.queryBlueToothIDisBindWithUnionId(connectedBluetoothid);

                }

            }else{
                console.log('当前选择设备未绑定过蓝牙：')

                if(connectedBluetoothid === '-1'){
                    console.log('连接蓝牙的是老版本设备无蓝牙协议，记录激活时间并返回连接成功');
                    self.recordOldBluetoothActiveTimeReq()
                    
                }else{
                    console.log('连接蓝牙的是新版本设备，取判断连接蓝牙是否绑定过设备');
                    self.queryBlueToothIDisBindWithUnionId(connectedBluetoothid);
                }

            }

        }
    }).catch(function(res:any){
        if(connectedBluetoothid === '-1'){
                console.log('连接蓝牙的是老版本设备无蓝牙协议，开始启动定时器刷新实时数据');
                self.connectSuccessAndHanerOther(true)
                
            }else{
                console.log('连接蓝牙的是新版本设备，取判断连接蓝牙是否绑定过设备');
                self.queryBlueToothIDisBindWithUnionId(connectedBluetoothid);
            }
    })

}
queryBlueToothIDisBindWithUnionId(unionId:string){//判断连接的蓝牙是否绑定过设备

    let self = this
    let thisDeviceId = User.tempChoosedEquipDeviceId;

    let param = {'bluetoothID':unionId};
    api.queryDeviceIdByBlueToothIdReq(param).then(function(res:any){
        console.log('根据设蓝牙协议id查设备id：'+JSON.stringify(res))

        if(res.success){
            let bindDeviceID = res.data.deviceID
            let bindDeviceNumber = res.data.deviceNumber

            console.log('当前连接蓝牙绑定的设备id：'+bindDeviceID)

            ////tofix
            // bindDeviceID = '12323'

            if(bindDeviceID !== null && bindDeviceID !== ''){
                console.log('当前连接蓝牙已绑定过设备了')
                if(thisDeviceId === bindDeviceID){
                    console.log("新版本蓝牙协议绑定过了设备，并且是当前连接的蓝牙，连接成功");
                    self.connectSuccessAndHanerOther(true)
                    User.connectDebiceBluetoothUnionid = unionId;

                }else{
                    console.log('新版本蓝牙协议绑定过了设备，但不是当前连接的蓝牙，蓝牙断开');
               
                    toast.hideLoading()

                    let msg = '当前ID:'+unionId+'的蓝牙，已被'+bindDeviceNumber+'设备绑定！'

                    // let msg = '蓝牙配对失败，该蓝牙ID'+unionId+'已被设备'+bindDeviceID+'绑定，请确认'
                    uni.showModal({
                        content: msg,
                        confirmText:'知道了',
                        showCancel:false,

                        success: function (res) {
                            if (res.confirm) {
                                self.closeBluetoothConnect()
                                router.back()
                            }
                        }
                    });
                }


            }else{
                console.log('当前连接蓝牙未绑定过设备，执行绑定操作');
                // self.bindBluetoothAndDevice(unionId);
                self.startBindDeviceTimer(unionId)

            }

            
        }

    }).catch(function(res:any){
        console.log('查询连接蓝牙绑定的设备id接口失败，执行绑定操作');
        // self.bindBluetoothAndDevice(unionId);
        self.startBindDeviceTimer(unionId)
    })
}
 startBindDeviceTimer(unionId:string){//开启绑定倒计时的定时器
    toast.hideLoading()
    this.bindTimeCounter = 10


    // toast.infoToast('连接失败');
    this.bindTimeCountTimer =  setInterval(() => {
        this.showBindBluetoothAlertView(unionId)
    }, 1000);
}
showBindBluetoothAlertView(unionId:string){ //展示绑定设备倒计时的弹窗
  
    console.log('上一次记录的运行状态：'+this.deviceLastOpenStatus+'，类型：'+typeof(this.deviceLastOpenStatus))
    console.log('上一次记录的控制方式：'+this.deviceLastModeStatus+'，类型：'+typeof(this.deviceLastModeStatus) )
    console.log('本次记录的运行状态：'+User.currentChoosedMachineBleData.engine_run_status+'，类型：'+typeof(User.currentChoosedMachineBleData.engine_run_status) )
    console.log('本次记录的控制方式：'+User.currentChoosedMachineBleData.control_status +'，类型：'+typeof(User.currentChoosedMachineBleData.control_status))



    if(this.deviceLastModeStatus.length > 0  || this.deviceLastOpenStatus.length > 0){

        console.log('进入判断流程，运行状态是否匹配：'+(this.deviceLastOpenStatus  !== User.currentChoosedMachineBleData.engine_run_status))
        console.log('进入判断流程，控制方式是否匹配：'+(this.deviceLastModeStatus  !== User.currentChoosedMachineBleData.control_status))

        if(this.deviceLastModeStatus  !== User.currentChoosedMachineBleData.control_status || 
           this.deviceLastOpenStatus  !== User.currentChoosedMachineBleData.engine_run_status
        ){

            this.isShowMatchBluetoothLoading = false;

            console.log('运行状态或者控制方式有变化，执行绑定动作')
            //运行状态或者控制方式和上一次不一样，就当做操作成功，执行绑定
            this.bindBluetoothAndDevice(unionId);

            this.stopBindDeviceTimer();
            return
        }
    }

    this.bindTimeCounter --;
    console.log('运行状态或者控制方式无变化，继续等待'+this.bindTimeCounter)


    if(this.bindTimeCounter <= 0){
        let self = this;
        this.isShowMatchBluetoothLoading = false;
        this.stopBindDeviceTimer();
        uni.showModal({
            content: '蓝牙配对超时，请重试！',
            confirmText:'知道了',
            showCancel:false,
            success: function (res:any) {
                if (res.confirm) {
                    console.log('蓝牙配对超时,关闭蓝牙')
                    self.connectSuccessAndHanerOther(false)
                   
                }
            }
        })
        return
    }else{

        let msg = '蓝牙配对中……\n请操作任意面板开关\n启动、自动、熄火）\n'
        let seconds =  this.bindTimeCounter+'s'
        console.log(msg+seconds)
        // toast.infoToast(msg)
    
        this.matchBluetoothTimerCount = this.bindTimeCounter;
        this.isShowMatchBluetoothLoading = true;
    

        this.deviceLastModeStatus =  User.currentChoosedMachineBleData.control_status;
        this.deviceLastOpenStatus =  User.currentChoosedMachineBleData.engine_run_status;
    
    
    }


}
stopBindDeviceTimer(){//结束绑定倒计时的定时器

    this.stopAutoRefreshTimer()

  if(this.bindTimeCountTimer){
    clearTimeout(this.bindTimeCountTimer);
    this.bindTimeCountTimer = -1;
  }
}

bindBluetoothAndDevice(unionId:string){//绑定设备和蓝牙
    let self = this
    let thisDeviceId = User.tempChoosedEquipDeviceId;

    let param = {'bluetoothID':unionId,
                    'deviceType':'wxmini',
                 'deviceID':thisDeviceId};
    console.log("绑定入参："+JSON.stringify(param));
    console.log("token："+User.getToken());
    api.bindBlueToothByUnionIdReq(param).then(function(res:any){

        console.log('绑定结果：'+JSON.stringify(res))
        if(res.success){
            console.log("绑定完成，返回连接成功："+JSON.stringify(res));
            self.connectSuccessAndHanerOther(true)
            User.connectDebiceBluetoothUnionid = unionId;
        }else{
            console.log("绑定报错"+res.message);

            if(res.message.includes('未关联')){
                console.log("未关联报错，当做新设备绑定");

                self.connectSuccessAndHanerOther(true)
                User.connectDebiceBluetoothUnionid = unionId;
            }else{
                console.log("弹出其他报错提示");

                let msg = res.message
                uni.showModal({
                    content: msg,
                    confirmText:'知道了',
                    showCancel:false,
                    success: function (res) {
                        if (res.confirm) {
                            self.connectSuccessAndHanerOther(false)
                            self.closeBluetoothConnect()
                            router.back()
                        }
                    }
                });
            }
        }
       
    }).catch(function(res:any){
        console.log("绑定失败，返回连接失败"+JSON.stringify(res));

        toast.hideLoading()

        let msg = '网络异常，请重试'
        uni.showModal({
            content: msg,
            confirmText:'知道了',
            showCancel:false,
            success: function (res) {
                if (res.confirm) {
                    self.closeBluetoothConnect()
                    self.connectFailedAndBackAction()
                }
            }
        });

      
    })
}

recordOldBluetoothActiveTimeReq(){
    

    let self = this
    let thisDeviceId = User.tempChoosedEquipDeviceId;

    let param = {'deviceID':thisDeviceId};
    console.log("旧蓝牙记录激活时间的入参："+JSON.stringify(param));

    api.recordOldBluetoothActiveTimeReq(param).then(function(res:any){

        console.log("旧蓝牙记录激活时间完成，返回连接成功："+JSON.stringify(res));
        self.connectSuccessAndHanerOther(true)
       
    }).catch(function(res:any){
        console.log("旧蓝牙记录激活时间失败，返回连接成功"+JSON.stringify(res));
        self.connectSuccessAndHanerOther(true)
    })
}

closeBluetoothConnect(){//断开蓝牙连接
    console.log('----------------------------')
    console.log('--------设备绑定流程中主动关闭蓝牙-----------')
    console.log('----------------------------')
    ///关闭蓝牙连接
    uni.closeBluetoothAdapter({
        success(res) {
            
        }
    });

    User.currentConnectedBlueTooth = {} as any;
    User.isTempConnectedBlueTooth = false;
    User.isConnectedBlueTooth = false;
    
    this.connectSuccessAndHanerOther(false)

}

//  -----------------蓝牙数据回写监听方法-----------------
    onListenBleData(){//开始监听蓝牙数据的回调
        console.log('开始监听')

        let self = this
        btUtil.notifyBluetoothValueCallback(function(){


            if(self.isReceiveData === false){
                return;
            }

            ///如果接收到实时数据就跳转设备才能返回
            if(User.isReceivedRuntimeData){

            

               
                User.isConnectedBlueTooth = true;


                // self.stopAutoRefreshTimer()

                console.log('接收到实时数据了，此时是否开始绑定判断'+self.isStartBluetoothBindStatus)

                if(self.isStartBluetoothBindStatus === false && User.bluetoothCallbackData.string_device_union_id_data !== '' && User.bluetoothCallbackData.string_device_union_id_data !== null){
                    console.log('进入绑定判断流程，此时的蓝牙协议id：'+User.bluetoothCallbackData.string_device_union_id_data)
                    console.log('进入绑定判断流程，当前连接的设备名称：'+User.currentTempChoosedEquipment.deviceName)

                    self.isStartBluetoothBindStatus = true

                            //查询蓝牙的唯一id
                            console.log('蓝牙协议id：'+User.bluetoothCallbackData.string_device_union_id_data)
                            //查到唯一id后，就进入判断流程
                            self.startBlueToothBindStatusProgress()
    
                    
                }
               
                if(self.isSendUnionIdCMD === false){
                    console.log('发送查询蓝牙协议id的指令');
                    self.isSendUnionIdCMD = true
                    self.queryBluetoothUnionId()

                }

            }



            
        })
    }

    connectSuccessAndHanerOther(isSuccess:boolean){
        this.stopAutoRefreshTimer();
        this.connectBluetoothCallback(isSuccess);

    }
    connectFailedAndBackAction(){
        this.stopAutoRefreshTimer();
            toast.infoToast('连接失败');
            setTimeout(() => {
            router.back()
            }, 1000);
     }

     ///结束全部定时器
     exportStopAllTimer(){
        console.log('绑定的定时器：'+this.bindTimeCountTimer)
        if(this.bindTimeCountTimer != -1){
            clearTimeout(this.bindTimeCountTimer);
            this.bindTimeCountTimer = -1;
        }
        if(this.autoRefreshTime != -1){
            clearTimeout(this.autoRefreshTime);
            this.autoRefreshTime = -1;
        }
     }
}


